/*
 * Created by 岱青海蓝信息系统(北京)有限公司 on 17-2-16 上午11:43
 * Copyright (c) 2017. All rights reserved.
 */

package com.example.dqhl.recycleviewdemo.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.example.dqhl.recycleviewdemo.R;
import com.example.dqhl.recycleviewdemo.adapter.MyAdapter;
import com.example.dqhl.recycleviewdemo.modle.MyModle;
import com.example.dqhl.recycleviewdemo.util.DividerGridItemDecoration;
import com.example.dqhl.recycleviewdemo.util.DividerItemDecoration;
import com.example.dqhl.recycleviewdemo.view.BannerIndicator;
import com.example.dqhl.recycleviewdemo.view.HIndicator;
import com.example.dqhl.recycleviewdemo.widget.WrapContentLinearLayoutManager;
import com.nostra13.universalimageloader.utils.L;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    //    @InjectView(R.id.recyceView) RecyclerView mRecyclerView;
    private MyAdapter myAdapter;
    private List<MyModle> mModleList = new ArrayList<>();
    private RecyclerView mRecyclerView;
    private BannerIndicator bannerIndicator;
    private HIndicator hIndicator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        ButterKnife.inject(this);

        mRecyclerView = (RecyclerView) findViewById(R.id.recyceView);
        bannerIndicator = (BannerIndicator) findViewById(R.id.indicator);
        hIndicator = (HIndicator) findViewById(R.id.hIndicator);
        hIndicator.setBgColor(Color.parseColor("#333333"));
        hIndicator.setIndicatorColor(Color.parseColor("#ffffff"));
        hIndicator.bindRecy(mRecyclerView);
        initData();

        //设置布局管理器
        //（1）竖屏的listview
//        final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
//        linearLayoutManager.setOrientation(LinearLayout.VERTICAL);
//        mRecyclerView.setLayoutManager(linearLayoutManager);

        mRecyclerView.setLayoutManager(new WrapContentLinearLayoutManager(this, true));

        //（2）横屏的gridview
//        mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));

        //（3）瀑布流
        //  数字代表几行
//        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        //设置Adapter
        mRecyclerView.setAdapter(myAdapter = new MyAdapter(this, mModleList));
        //设置Item增加、移除动画
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        //添加分割线

        //竖屏的listview
        mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST));

        //横屏的gridview
//        mRecyclerView.addItemDecoration(new DividerGridItemDecoration(this));

        myAdapter.setOnItemClickListener(new MyAdapter.onItemClickListener() {
            //点击每一项增加
            @Override
            public void onItemClick(View view, int position) {
                Toast.makeText(MainActivity.this, position + " click",
                        Toast.LENGTH_SHORT).show();
                myAdapter.addData(1);
            }

            //长按删除
            @Override
            public void onItemLongClick(View view, int position) {
                Toast.makeText(MainActivity.this, position + " long click",
                        Toast.LENGTH_SHORT).show();
                myAdapter.removeData(position);
            }
        });
    }

    private void initData() {
        mModleList = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            mModleList.add(new MyModle("猴"));
            mModleList.add(new MyModle("猴子"));
            mModleList.add(new MyModle("猴子要"));
            mModleList.add(new MyModle("猴子要理"));
            mModleList.add(new MyModle("猴子要理发"));
            mModleList.add(new MyModle("猴子要理发嫩"));
            mModleList.add(new MyModle("猴子要理发嫩猴"));
            mModleList.add(new MyModle("猴子要理发嫩猴子"));
            mModleList.add(new MyModle(i + "猴"));
            mModleList.add(new MyModle("猴子要理发嫩猴子要理发嫩"));
            mModleList.add(new MyModle(i + "猴猴子"));
        }
        bannerIndicator.setNumber(6);
    }
}
